//JavaScript Framework 2.0 Code
try{
Type.registerNamespace('com.yonyou.ncmm_pac_pda.FinProdInMakeEditController');
com.yonyou.ncmm_pac_pda.FinProdInMakeEditController = function() {
    com.yonyou.ncmm_pac_pda.FinProdInMakeEditController.initializeBase(this);
    this.initialize();
}
function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$initialize(){
    //you can programing by $ctx API
    //get the context data through $ctx.get()
    //set the context data through $ctx.push(json)
    //set the field of the context through $ctx.put(fieldName, fieldValue)
    //get the parameter of the context through $ctx.param(parameterName)
    //Demo Code:
    //    var str = $ctx.getString();      //获取当前Context对应的字符串
    //    alert($ctx.getString())          //alert当前Context对应的字符串
    //    var json = $ctx.getJSONObject(); //获取当前Context，返回值为json
    //    json["x"] = "a";        //为当前json增加字段
    //    json["y"] = [];           //为当前json增加数组
    //    $ctx.push(json);            //设置context，并自动调用数据绑定
    //    
    //    put方法需手动调用databind()
    //    var x = $ctx.get("x");    //获取x字段值
    //    $ctx.put("x", "b");     //设置x字段值
    //    $ctx.put("x", "b");     //设置x字段值
    //    $ctx.databind();            //调用数据绑定才能将修改的字段绑定到控件上
    //    var p1 = $param.getString("p1");   //获取参数p2的值，返回一个字符串
    //    var p2 = $param.getJSONObject("p2");   //获取参数p3的值，返回一个JSON对象
    //    var p3 = $param.getJSONArray("p3");   //获取参数p1的值，返回一个数组
    
    //your initialize code below...
    
}
    
	function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$evaljs(js){
    	eval(js)
	}
	
	function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$stockoutRef(sender, args){
    	var stockorg = $cache.read("defaultstockorg");
    	if(stockorg == null || stockorg == "") {
        	$alert("默认库存组织不能为空，请设置！");
        	return;
    	}
    	stockorg = $stringToJSON(stockorg);
    	stockorg = stockorg["pk_stockorg"];
    	openStordocRefPage("PDASTORDOC", "cwarehouseid_name", "cwarehouseid", "pk_stordoc", stockorg);
	    $ctx.put("pk_rack_name", "");
		$ctx.put("pk_rack", "");
		$ctx.dataBind();			
	}
	
	function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$stockinRef(sender, args){
    	var stockorg = $cache.read("defaultstockorg");
    	if(stockorg == null || stockorg == "") {
        	$alert("默认库存组织不能为空，请设置！");
        	return;
    	}
    	stockorg = $stringToJSON(stockorg);
    	stockorg = stockorg["pk_stockorg"];
    	openStordocRefPage("PDASTORDOC", "cotherwhid_name", "cotherwhid", "pk_stordoc", stockorg);
	}

	function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$locationRef(sender, args){
//   	var stocrdoc = $cache.read("defaultstordoc");
//   	if(stocrdoc == null || stocrdoc == "") {
//       	$alert("默认库存组织不能为空，请设置！");
//       	return;
//   	}
//   	stocrdoc = $stringToJSON(stocrdoc);
//    	stocrdoc = stocrdoc["pk_stordoc"];
        var stocrdoc = $ctx.getString("cwarehouseid");
    	openRackRefPage("PDARACK", "pk_rack_name", "pk_rack", "pk_rack", stocrdoc);
	}

	function onScantxtInput(sender, args){
    	$ctx.dataCollect();
    	var marbarcode = $ctx.getString("vbarcode");
    	parseMarCode(marbarcode);
    	$id("textbox0").set("value", null);
    	$id("textbox0").focus();
	}

    //解析物料码
    function parseMarCode(marbarcode) {
        var listJson = $ctx.getJSONObject();
        if(NCMMPubUtil.isEmpty(marbarcode)) {
			$alert("物料码为空！");
			return;
		}
		var marJson = NCMMBarcodeParseUtil.parseMaterialBar(marbarcode);
		var marID = marJson.pk_material;
		if(NCMMPubUtil.isEmpty(marID)) {
		    $alert(marJson.failmsg);
			return;
		}
		listJson["cmaterialvid"] = marJson.pk_material;
		listJson["cinvcode"] = marJson.code;
		var conditon = " where pk_material='" + marJson.pk_material + "'";
		var results = NCMMPubUtil.queryVONoCallback(MaterialVO, conditon);
		if(NCMMPubUtil.isEmpty(results) || results == "[]") {
			$alert("不存在当前物料，请更新物料档案！");
			return;
		}
		//$alert("扫描物料主键："+marJson.pk_material);
		//$alert("扫描物料数量："+results.length);
		results = $stringToJSON(results);
		//$alert("扫描物料："+results);
		if(results.length == 1) {
		    listJson["cinvname"] = results[0].name;
		    listJson["materialspec"] = results[0].materialspec;
		    listJson["materialtype"] = results[0].materialtype;
		    //主单位
		    listJson["cunitid"] = results[0].pk_measdoc;
		    listJson["cunitid_name"] = results[0].pk_measdoc_name;
		    //辅单位默认取和主单位一样
		    listJson["castunitid"] = results[0].pk_measdoc;
		    listJson["vchangerate"]="1/1";
		    listJson["castunitid_name"] = results[0].pk_measdoc_name;
		    var conditionconvert=" where pk_material='"+results[0].pk_material+"' and isstockmeasdoc='Y'";
		    var converts = NCMMPubUtil.queryVONoCallback(MaterialConvertVO, conditionconvert);
		    if(NCMMPubUtil.isNotEmpty(converts) && NCMMPubUtil.isNotEmpty(converts[0])) {
		      var convert = $stringToJSON(converts[0]);
			   //辅单位取物料档案下默认库存单位
		      listJson["castunitid"]=convert.pk_measdoc;
		       //和库存单位换算率
		      listJson["vchangerate"]=convert.vchangerate;
		      listJson["castunitid_name"] = convert.measdoc_name;
		    }
		    
		    //辅单位名称从计量单位档案获取
		   // var conditionunit = " where pk_measdoc = '" + results[0].stockmeasdoc + "'";
		    //var unitresults = NCMMPubUtil.queryVONoCallback(MeasdocVO, conditionunit);
		   // if(NCMMPubUtil.isEmpty(unitresults) || results == "[]") {
			//    $alert("不存在当前物料默认库存单位，请更新计量单位档案！");
			//    return;
		    //}
		    //unitresults = $stringToJSON(unitresults);
		    //listJson["castunitid_name"] = unitresults[0].name;
		}
		if(NCMMPubUtil.isNotEmpty(marJson.vbatchcode)) {
			listJson["vbatchcode"] = marJson.vbatchcode;
			listJson["pk_batchcode"] = marJson.pk_batch;
		}
		listJson["vserialcode"] = marJson.vserialcode;
		/*if (!marJson.scannum || marJson.scannum == "" || marJson.scannum == null) {
		   listJson["nnum"] = 1; 
		} else {
		   listJson["nnum"] = marJson.scannum;
		}*/
		//listJson["nastnum"] = 1;
		var num=1;
		var vchangerate = listJson["vchangerate"];
		var nastnum = FinProdInMakeUtil.getAstnum(1, vchangerate);        
        if(NCMMPubUtil.isNotEmpty(marJson.nnum)){
           num=marJson.nnum;
           nastnum=FinProdInMakeUtil.getAstnum(num, vchangerate);
        }else if(NCMMPubUtil.isNotEmpty(marJson.nassistnum)){
           nastnum=marJson.nassistnum;
           num=FinProdInMakeUtil.getNum(nastnum,vchangerate);
        }
        var bitnum = FinProdInMakeUtil.getUnitBitnumber(listJson["cunitid"]);
        if(!NCMMPubUtil.isEmpty(bitnum)) {
           num = num.toFixed(bitnum);
        }
        var astbitnum = FinProdInMakeUtil.getUnitBitnumber(listJson["castunitid"]);
        if(!NCMMPubUtil.isEmpty(astbitnum)) {
           nastnum = nastnum.toFixed(astbitnum);
        }
        listJson["nassistnum"]=nastnum;
        listJson["nnum"] =num;
		listJson["nastnum"] = FinProdInMakeUtil.getNastum(listJson["nnum"], listJson["vchangerate"]);
		//组织默认取业务设置默认组织
		var stockorg = $cache.read("defaultstockorg") ? $cache.read("defaultstockorg") : "";
		if(stockorg != "") {
			stockorg = $stringToJSON(stockorg);
			var stockorgid = stockorg["pk_stockorg"];
		}
		listJson["pk_org"] = stockorgid;
		if(NCMMPubUtil.isEmpty(listJson["cbilltypeid"])) {
			$alert("入库类型不能为空！");
			return;
		}
		if(NCMMPubUtil.isEmpty(listJson["cwarehouseid"])) {
			$alert("入库仓库不能为空！");
			return;
		}
		listJson["pk_scan"] = getFinProdInMakeScanPK();
		NCMMPubUtil.insertVO(FinProdInMakeVO, listJson);
		$ctx.push(listJson);
    }

	//计算浮动换算率
	function getvchangerate(nnum, nastnum) {
	    var vchangerate;
	    var num = nnum / nastnum;
	    num = num.toFixed(3);
	    vchangerate = num.toString()+"/1";
	    return vchangerate;
	}
	
	
	function getRefParam(reftype, callback) {
	    var condition = {
			"ncbillcode": reftype
		};
		NCMMPubUtil.queryVOByConditions(AppmappingheadVO, condition, function(data) {
			var jsondata = {
				bdlistdata: eval(data)
			};
			//$alert(jsondata);
			var reftitle = (jsondata.bdlistdata)[0]["appbillname"];
			if((jsondata.bdlistdata)[0]["downloadnum"] == "" || (jsondata.bdlistdata)[0]["downloadnum"] == "0") {
				$alert("【" + reftitle + "】没有可参照的数据");
				if(callback != null && callback != undefined && typeof(callback) == 'function') {
					callback(null);
				}
				return;
			}
			var reftablename = (jsondata.bdlistdata)[0]["apptablename"]; //本地表名
			var jsonparam = {
				reftype: reftype, //外系统调用标识
				reftitle: reftitle, //元数据显示名称
				reftablename: reftablename //本地表名
			};
			if(callback != null && callback != undefined && typeof(callback) == 'function') {
				callback(jsonparam);
			}
		});
	}
	
	// 打开仓库参照页面
	function openStordocRefPage(ncbillcode, ctxnamekey, ctxpkkey, pkfiel, pk_stockorg) {
		var jsonparam = {};
		getRefParam(ncbillcode, function(data) {
			jsonparam = data;
		});

		if(jsonparam == null) {
			//$alert("jsonparam is null!");
			return;
		}

		jsonparam["wheresql"] = " where pk_stock='" + pk_stockorg + "'";
		console.log(jsonparam["wheresql"]);
		$view.open({
			viewid: "com.yonyou.ncmm_pac_pda.RefPage", //目标页面
			isKeep: "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
			data: jsonparam,
			callback: function() {
				var refdata = $param.getJSONObject("data");
				$ctx.put(ctxnamekey, refdata["name"]);
				$ctx.put(ctxpkkey, refdata[pkfiel]);
				$ctx.dataBind();				
			}
		});
	}
	
	// 打开货位参照页面
	function openRackRefPage(ncbillcode, ctxnamekey, ctxpkkey, pkfiel, pk_stordoc) {
		var jsonparam = {};
		getRefParam(ncbillcode, function(data) {
			jsonparam = data;
		});

		if(jsonparam == null) {
			//$alert("jsonparam is null!");
			return;
		}

		jsonparam["wheresql"] = " where pk_stordoc='" + pk_stordoc + "'";
		console.log(jsonparam["wheresql"]);
		$view.open({
			viewid: "com.yonyou.ncmm_pac_pda.RefPage", //目标页面
			isKeep: "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
			data: jsonparam,
			callback: function() {
				var refdata = $param.getJSONObject("data");
				$ctx.put(ctxnamekey, refdata["name"]);
				$ctx.put(ctxpkkey, refdata[pkfiel]);
				$ctx.dataBind();				
			}
		});
	}

function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$onload(sender, args){
    var row = $param.getJSONObject("row");
    NCMMPubUtil.createTable(FinProdInMakeVO);
    if(!(row == null || row == "")) {
        var json = {};
        json = row;
        json = NCMMPubUtil.htmlspecialjson2UI(json);
        $ctx.push(json);
        $ctx.dataBind();
    }
    else{
        var stordoc = $cache.read("defaultstordoc") ? $cache.read("defaultstordoc") : "";
	    if(stordoc != "") {
			stordoc = $stringToJSON(stordoc);
			$ctx.put("cwarehouseid", NCMMPubUtil.htmlspecialchars2UI(stordoc["pk_stordoc"]));
			$ctx.put("cwarehouseid_name", NCMMPubUtil.htmlspecialchars2UI(stordoc["name"]));
			$ctx.dataBind();
		}
        var billtype = $cache.read("default46billtype") ? $cache.read("default46billtype") : "";
	    if(billtype != "") {
			billtype = $stringToJSON(billtype);
			$ctx.put("cbilltypeid", NCMMPubUtil.htmlspecialchars2UI(billtype["pk_billtypeid"]));
			$ctx.put("cbilltypeid_name", NCMMPubUtil.htmlspecialchars2UI(billtype["name"]));
			$ctx.dataBind();
		}
    }
}
function back(sender, args){
    $view.close();
}
function loadmenu(sender, args){
    FinProdInMakeUtil.openDropDownListForScan("btn_menu");
}
function localSave(sender, args){
    var json = $ctx.getJSONObject();
    if(json.nnum == null || json.nnum == 0 || json.nnum == "0") {
        $alert("主数量不能为空或0！");
        return;
    }
    if(json.nastnum == null || json.nastnum == 0 || json.nastnum == "0") {
        $alert("数量不能为空或0！");
        return;
    }
    if(!$.isNumeric(json.nnum) || !$.isNumeric(json.nastnum)) {
        $alert("数量输入不合法！");
        return;
    }
    json = NCMMPubUtil.htmlspecialjson2UI(json);
    var isSuccess = doSave(json);
    if(isSuccess == true) {
        $toast("保存成功！");
    }
}

function doSave(json) {
    //如果批次号修改过
    //if(NCMMPubUtil.isEmpty(json["vbatchcode"])) {
        json["pk_batchcode"] = "";
    /*} else {
        if(NCMMPubUtil.isTableExist(BatchcodeVO)) {
            var sql = " where vbatchcode='" + json["vbatchcode"] + "' and cmaterialvid='" + json["cmaterialvid"] + "'";
            var pk_batchcode = "";
            NCMMPubUtil.queryVO(BatchcodeVO, sql, function(data) {
                if(typeof(data) == 'undefined' || data == null || data.length == 0) {
                    return;
                } else {
                    var vos = eval(data);
                    if(vos != null && vos.length > 0) {
                        pk_batchcode = vos[0].pk_batchcode;
                    }
                }
            });
        }
        if(NCMMPubUtil.isEmpty(pk_batchcode)) {
            $alert("批次号不在批次档案中，请检查输入或更新批次档案！");
            return false;
        }
        json["pk_batchcode"] = pk_batchcode;
    }*/
   if(NCMMPubUtil.isEmpty(json["cbilltypeid"])) {
			$alert("入库类型不能为空！");
			return;
		}
		if(NCMMPubUtil.isEmpty(json["cwarehouseid"])) {
			$alert("入库仓库不能为空！");
			return;
		}
    if(NCMMPubUtil.isEmpty(json["pk_scan"])) {
        json["pk_scan"] = getFinProdInMakeScanPK();
        console.log("json = "+$jsonToString(json));
        NCMMPubUtil.insertVO(FinProdInMakeVO, json);
    } else {
        console.log("json = "+$jsonToString(json));
        NCMMPubUtil.updateVO(FinProdInMakeVO, json);
    }
    $ctx.push(json);
    $ctx.dataBind();
    return true;
}

function getFinProdInMakeScanPK() {
    var date = new Date().getTime();
    var pk = "40080604TM" + date.toString();
    return pk;
}

function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$imagebutton0_onclick(sender, args){
    $scanner.open({
        bindfield: "vbarcode",
        callback: "onScantxtInput()"
    });
}

	function marScanBack() {
		var marbarcode = $ctx.getString("vbarcode");
		if(marbarcode != null && marbarcode != "") {
			// 扫描的是物料码
			$id("textbox0").set("value", marbarcode);
			$ctx.dataBind();
		}
		parseMarCode(marbarcode);
		$id("textbox0").set("value", null);
	}

//提交
function onOneScanSubmit(sender, args){
    var json = $ctx.getJSONObject();
    if (NCMMPubUtil.isEmpty(json)) {
        $alert("无扫描数据，不能提交！");
        return;
    }
    if(json.nnum == null || json.nnum == 0 || json.nnum == "0") {
        $alert("主数量不能为空或0！");
        return;
    }
    if(json.nastnum == null || json.nastnum == 0 || json.nastnum == "0") {
        $alert("数量不能为空或0！");
        return;
    }
    if(!$.isNumeric(json.nnum) || !$.isNumeric(json.nastnum)) {
        $alert("数量输入不合法！");
        return;
    }
	json = NCMMPubUtil.htmlspecialjson2UI(json);
	var isSuccess = doSave(json);
	if(isSuccess != true) {
	    $js.hideLoadingBar();
	    return;
	}
	var sql = " where pk_scan='" + json.pk_scan + "'";
	var vo = null;
	NCMMPubUtil.queryVO(FinProdInMakeVO, sql, function(scanData) {
	    if(typeof(scanData) == 'undefined' || scanData == null || scanData.length == 0) {
	        return;
	    }
	    var vos = eval(scanData);
	    vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
	    vo = vos[0];
	});
	if(NCMMPubUtil.isEmpty(vo)) {
	    $js.hideLoadingBar();
	    $alert("当前扫描记录已经被删除，不能提交！")
	    return;
	}
	var head = {};
	head["pk_org"] = vo["pk_org"];
    head["cwarehouseid"] = vo["cwarehouseid"];
    head["cbilltypeid"]=vo["cbilltypeid"];
    var item = {};
    item["cmaterialvid"] = vo["cmaterialvid"];
    item["nshouldassistnum"] = vo["nastnum"];
    item["nshouldnum"] = vo["nnum"];
    item["castunitid"] = vo["castunitid"];
    item["cunitid"] = vo["cunitid"];
    item["vchangerate"] = vo["vchangerate"];
    item["vbatchcode"]=vo["vbatchcode"];
    //$alert($jsonToString(vo));
    if(NCMMPubUtil.isNotEmpty(vo["vserialcode"]) || NCMMPubUtil.isNotEmpty(vo["pk_rack"])){
     var bbitems=[];
     var bbitem={};
     bbitem["vserialcode"]=vo["vserialcode"];
     bbitem["clocationid"]=vo["pk_rack"];
     bbitem["nnum"]=(vo["nnum"] == "" ? "1.00000" : vo["nnum"]);
     bbitems.push({"bbitem":bbitem});
     item["bbitems"]=bbitems;
    }
    var billinfo = {};
    billinfo["head"] = head;
    var items = [{
	    "item": item
	}];
	billinfo["items"] = items;
	var billinfos = [{
	    "billinfo": billinfo
	}];
	//$alert($jsonToString(billinfos));
	var submitvos = [];
	submitvos.push(vo);
	$js.showLoadingBar();
	//测试连接
	NCMMDBUtil.testNCConnection(function(data) {
	    if(data == false || data == "false") {
	        $js.hideLoadingBar();
	        $toast("连接服务器失败，无法提交！");
			return;
	    } else {
	        NCMMDBUtil.submitLocaldataToNC("46make", billinfos, function(commitInfo) {
	            if(!NCMMPubUtil.isEmpty(commitInfo)) {
	                if(commitInfo.return == null || commitInfo.return == "") {
	                    $js.hideLoadingBar();
	                    $alert("提交失败：" + $jsonToString(commitInfo));
	                } else if(commitInfo["return"].returnFlag == 1) {
	                    FinProdInMakeUtil.deleteaftersubmit(submitvos);
	                    var list = {
	                    "cbilltypeid":vo["cbilltypeid"],
	                    "cbilltypeid_name":vo["cbilltypeid_name"],
	                    "cwarehouseid":vo["cwarehouseid"],
	                    "cwarehouseid_name":vo["cwarehouseid_name"],
	                    };
	                    $ctx.push(list);
	                    $js.hideLoadingBar();
                        $toast("提交成功！");
	                } else {
	                    $js.hideLoadingBar();
	                    $alert("提交失败" + $jsonToString(commitInfo.return.returnDesc));
	                }
	            } else {
	                $js.hideLoadingBar();
	                $alert("提交失败");
	            }
	        });
	    }
	});
}
function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$oninputNum(sender, args){
		$ctx.dataCollect();
		var num = $ctx.getString("nnum");
		if(num == null || num == "" || num == "-") {
			$ctx.put("nastnum", num);
			$ctx.dataBind();
			return;
		}
		if(!FinProdInMakeUtil.isNumber(num)) {
			//此时第一次输入
			var astnum = $ctx.getString("nastnum");
			if(astnum == null || astnum == "") {
				$ctx.put("nnum", "");
			} else {
				$ctx.put("nnum", args["oldvalue"]);
			}
			$ctx.dataBind();
			return;
		}
		if(!FinProdInMakeUtil.validateNumScale(num, $ctx.getString("cunitid"))) {
			$ctx.put("nnum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}
		var vchangerate = $ctx.getString("vchangerate");
		var astnum = FinProdInMakeUtil.getNastum(num, vchangerate);
		astnum = FinProdInMakeUtil.getScaleNum(astnum, $ctx.getString("castunitid"));
		$ctx.put("nastnum", astnum);
		$ctx.dataBind();

}
function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$inputAstNum(sender, args){
        $ctx.dataCollect();
		var astnum = $ctx.getString("nastnum");
		if(astnum == null || astnum == "" || astnum == "-") {
			$ctx.put("nnum", astnum);
			$ctx.dataBind();
			return;
		}
		if(!FinProdInMakeUtil.isNumber(astnum)) {
			//此时第一次输入
			var num = $ctx.getString("nnum");
			if(num == null || num == "") {
				$ctx.put("nastnum", "");
				$ctx.put("nnum", "");
				$ctx.dataBind();
			} else {
				$ctx.put("nastnum", args["oldvalue"]);
				$ctx.dataBind();
			}
			return;
		}
		if(!FinProdInMakeUtil.validateNumScale(astnum, $ctx.getString("castunitid"))) {
			$ctx.put("nastnum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}
		var vchangerate = $ctx.getString("vchangerate");
		var num = FinProdInMakeUtil.getNum(astnum, vchangerate);
		num = FinProdInMakeUtil.getScaleNum(num, $ctx.getString("cunitid"));
		$ctx.put("nnum", num);
		$ctx.dataBind();

}
function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$cspaceScan(sender, args){
   $scanner.open({
			bindfield: "rack",
			callback: "rackScanBack()"
		});
}
function rackScanBack() {
		var rack = $ctx.getString("rack");
		var wheresql = " where code='" + rack + "'";
		var stordoc = $ctx.getString("cwarehouseid");
		if(!NCMMPubUtil.isEmpty(stordoc)) {
			wheresql = wheresql + " and pk_stordoc='" + stordoc + "'";
		}
		getRackInfoByWhereSql(wheresql, rack);
	}
	
	function getRackInfoByWhereSql(wheresql, rack) {
		if(NCMMPubUtil.isTableExist(RackVO) == false) {
			$alert("没有扫描货位【" + rack + "】记录，请更新货位数据，或检查当前扫描货位是否属于默认仓库！");
			$ctx.put("pk_rack_name", "");
			$ctx.put("pk_rack", "");
			$ctx.dataBind();
			return;
		}
		NCMMPubUtil.queryVO(RackVO, wheresql, function(data) {
			//2 打开扫描记录编辑界面
			if(NCMMPubUtil.isEmpty(data)) {
				$alert("没有扫描货位【" + rack + "】记录，请更新货位数据，或检查当前扫描货位是否属于默认仓库！");
				$ctx.put("pk_rack_name", "");
				$ctx.put("pk_rack", "");
				$ctx.dataBind();
				return;
			}
			var vos = eval(data);
			$ctx.put("pk_rack_name", vos[0].name);
			$ctx.put("pk_rack", vos[0].pk_rack);
			$ctx.dataBind();
		});
	}
function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$billtypeRef(sender, args){
openBilltypeRefPage("PDABILLTYPE", "cbilltypeid_name", "cbilltypeid", "pk_billtypeid");
	
}
// 打开出库类型参照页面
	function openBilltypeRefPage(ncbillcode, ctxnamekey, ctxpkkey, pkfiel) {
		var jsonparam = {};
		getRefParam(ncbillcode, function(data) {
			jsonparam = data;
		});

		if(jsonparam == null) {
			//$alert("jsonparam is null!");
			return;
		}

		jsonparam["wheresql"] = " where parentbilltype='46'";
		console.log(jsonparam["wheresql"]);
		$view.open({
			viewid: "com.yonyou.ncmm_pac_pda.RefPage", //目标页面
			isKeep: "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
			data: jsonparam,
			callback: function() {
				var refdata = $param.getJSONObject("data");
				$ctx.put(ctxnamekey, refdata["name"]);
				$ctx.put(ctxpkkey, refdata[pkfiel]);
				$ctx.dataBind();				
			}
		});
	}
function com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$astUnitRef(sender, args){
   var listJson = $ctx.getJSONObject();
   var mateiralID=listJson.cmaterialvid;
   if(NCMMPubUtil.isEmpty(mateiralID)){
     $alert("请先扫描物料！");
     return;
   }
   NCMMPubUtil.openAstUnitRefPage("castunitid_name", "castunitid", "vchangerate", mateiralID,"nnum","nastnum");

}
function rackEdit(sender, args){
     var stocrdoc = $ctx.getString("cwarehouseid");
		if(NCMMPubUtil.isEmpty(stocrdoc)) {
			$alert("仓库不能为空！");
			$ctx.put("pk_rack_name", "");
			$ctx.put("pk_rack", "");
			$ctx.dataBind();
			return;
		}
		var rack = $ctx.getString("pk_rack_name");
		var wheresql = " where (code='" + rack + "' or name ='" + rack + "')";
		if(!NCMMPubUtil.isEmpty(stocrdoc)) {
			wheresql = wheresql + " and pk_stordoc='" + stocrdoc+ "'";
		}
		getRackInfoByWhereSql(wheresql, rack);
}
com.yonyou.ncmm_pac_pda.FinProdInMakeEditController.prototype = {
    astUnitRef : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$astUnitRef,
    billtypeRef : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$billtypeRef,
    cspaceScan : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$cspaceScan,
    inputAstNum : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$inputAstNum,
    oninputNum : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$oninputNum,
    locationRef : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$locationRef,
    stockoutRef : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$stockoutRef,
    stockinRef : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$stockinRef,
    imagebutton0_onclick : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$imagebutton0_onclick,
    onload : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$onload,
    initialize : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$initialize,
    evaljs : com$yonyou$ncmm_pac_pda$FinProdInMakeEditController$evaljs
};
com.yonyou.ncmm_pac_pda.FinProdInMakeEditController.registerClass('com.yonyou.ncmm_pac_pda.FinProdInMakeEditController',UMP.UI.Mvc.Controller);
}catch(e){$e(e);}
